package com.dailyblue.java.spring.boot.redis.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/map")
@Slf4j
public class MapRedisController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping
    public void a() {
        HashOperations hash = stringRedisTemplate.opsForHash();
        hash.put("A", "A", "1");
        hash.put("A", "B", "bb");
        hash.put("A", "C", "cc");
        hash.put("A", "B", "dd");
        Object v1 = hash.get("A", "B");
        log.info("v1:{}", v1);
        Map map1 = hash.entries("A");
        log.info("map1:{}",map1);
        Set set1 = hash.keys("A");
        Collection list1 = hash.values("A");
        log.info("keys:{},values:{}",set1,list1);
        hash.delete("A","C");
    }
}
